package com.youbang.bsMgr.role.dao;

import com.youbang.bsMgr.role.model.RoleEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface RoleMapper {
    /**
     * 根据主键删除
     *
     * @param id
     * @return
     */
    int deleteByPrimaryKey(@Param("id") int id);

    /**
     * 插入
     *
     * @param record
     * @return
     */
    @Insert("insert into t_role (id, roleName, roleDesc,enable)values (#{record.id}, #{record.rolename}, #{record.roledesc},#{record.enable})")
    @Options(useGeneratedKeys = true, keyProperty = "record.id",keyColumn="id")
    int insert(@Param("record") RoleEntity record);

    /**
     * 查看详情
     *
     * @param id
     * @return
     */
    RoleEntity selectByPrimaryKey(@Param("id")int id);


    /**
     * 更新
     *
     * @param record
     * @return
     */
    @Update(" update t_role\n" +
            "    set roleName = #{record.rolename,jdbcType=VARCHAR},\n" +
            "      roleDesc = #{record.roledesc,jdbcType=VARCHAR},\n" +
            "      enable = #{record.enable,jdbcType=BIT}\n" +
            "    where id = #{record.id,jdbcType=INTEGER}")
    int updateByPrimaryKey(@Param("record")RoleEntity record);

    @Select("<script> select * from t_role <when test='searchRoleName!=null'> where roleName like '%${searchRoleName }%' </when> order by id desc limit #{startIndex} , #{endIndex} </script>")
    List<RoleEntity> GetAllRole(@Param("endIndex")Integer endIndex,@Param("startIndex")Integer startIndex,@Param("searchRoleName") String searchRoleName);
    @Select("<script> select count(*) from t_role <when test='searchRoleName!=null'> where roleName like '%${searchRoleName }%' </when> order by id desc </script>")
    int GetAllRoleCout( @Param("searchRoleName")String searchRoleName);
}